package com.ebelter.btlibrary.util;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

/**
 * 吐司提示类
 * @author	fenghui
 * @date	2014年9月9日
 *
 */
public class UToast {

	private static Toast toastLong = null;
	private static Toast toastShort = null;

	public static void ShowShort(Context context, String content)
	{
		if (toastShort == null) {
			toastShort = Toast.makeText(context, content, Toast.LENGTH_SHORT);
		} else {
			toastShort.setText(content);
		}
		toastShort.show();
	}

	public static void ShowShort(Context context, int resId)
	{
		if (toastShort == null) {
			toastShort = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
		} else {
			toastShort.setText(resId);
		}
		toastShort.show();
	}

	public static void ShowLong(Context context, String content)
	{
		if (toastLong == null) {
			toastLong = Toast.makeText(context, content, Toast.LENGTH_LONG);
		} else {
			toastLong.setText(content);
		}
		toastLong.show();
	}

	public static void ShowLong(Context context, int resId)
	{
		if (toastLong == null) {
			toastLong = Toast.makeText(context, resId, Toast.LENGTH_LONG);
		} else {
			toastLong.setText(resId);
		}
		toastLong.show();
	}

	public static void ShowTask(final Context context, final String content)
	{
		//让其在主线程(UI线程)中运行
		new Handler(Looper.getMainLooper()).post(new Runnable(){
			@Override
			public void run() {
				Toast.makeText(context, content, Toast.LENGTH_SHORT).show();
			}
		});
	}
}